package com.lovo.pis.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.pis.dto.CountBean;
import com.lovo.pis.dto.SellGoodsBean;
import com.lovo.pis.mapper.SellGoodsMapper;
import com.lovo.pis.service.ISellGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SellGoodsServiceImpl extends ServiceImpl<SellGoodsMapper, SellGoodsBean> implements ISellGoodsService {

    @Autowired
    SellGoodsMapper sellGoodsMapper;


    @Override
    public List<CountBean> getSellGoodsTypeCount(String startDate, String endDate) {
        return sellGoodsMapper.selectGoodsTypeCount(startDate,endDate);
    }

    @Override
    public List<CountBean> getSellGoodsNameCount(String startDate, String endDate) {
        return sellGoodsMapper.selectGoodsNameCount(startDate,endDate);
    }

    @Override
    public List<List<Object>> getMonthSellCount(String year) {
        String month = "";
        boolean dn = false;boolean rc = false;boolean bg = false;boolean af = false;
        List<Object> headList = new ArrayList<>(){{
            add(0,"月份");add(1,"一月");add(2,"二月");
            add(3,"三月");add(4,"四月");add(5,"五月");
            add(6,"六月");add(7,"七月");add(8,"八月");
            add(9,"九月");add(10,"十月");add(11,"十一月");add(12,"十二月");
        }};
        List<Object> dnList = new ArrayList<>(){{add(0,"电脑产品");}};
        List<Object> rcList = new ArrayList<>(){{add(0,"日常产品");}};
        List<Object> bgList = new ArrayList<>(){{add(0,"办公耗材");}};
        List<Object> afList = new ArrayList<>(){{add(0,"安防产品");}};
        for (int i = 0; i < 12; i++) {
            if (i<9){
                 month = "0"+(i+1);
            }else {
                month=String.valueOf(i+1);
            }
           List<CountBean> list = sellGoodsMapper.selectMonthSellCount(year,month);
            for (int j = 0; j < list.size(); j++) {
                if ("电脑产品".equals(list.get(j).getName())){
                    dnList.add(i+1,list.get(j).getValue());
                    dn=true;
                }
                if ("日常产品".equals(list.get(j).getName())){
                    rcList.add(i+1,list.get(j).getValue());
                    rc=true;
                }
                if ("办公耗材".equals(list.get(j).getName())){
                    bgList.add(i+1,list.get(j).getValue());
                    bg=true;
                }
                if ("安防产品".equals(list.get(j).getName())){
                    afList.add(i+1,list.get(j).getValue());
                    af=true;
                }
            }
            if (!dn){
                dnList.add(i+1,0);
            }
            if (!rc){
                rcList.add(i+1,0);
            }
            if (!bg){
                bgList.add(i+1,0);
            }
            if (!af){
                afList.add(i+1,0);
            }
            dn=false;rc=false;bg=false;af=false;
        }
        List<List<Object>> dataList = new ArrayList<>(){{
            add(headList);add(dnList);add(rcList);add(bgList);add(afList);
        }};
        return dataList;
    }

}

